<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Register</title>
    <link href="layui/css/layui.css" rel="stylesheet">
    <link rel="stylesheet" href="./login_style//css/admin.css">
    <link rel="stylesheet" href="./login_style/css/login.css">

</head>
<body >

<div class="layadmin-user-login layadmin-user-display-show"  >
    <div class="layadmin-user-login-main ">
        <div class="layadmin-user-login-box layadmin-user-login-header" style="padding: 0px !important;">
            <h2>Admin</h2>
            <p>邑大人事管理系统</p>
        </div>
        <from class="layadmin-user-login-box layadmin-user-login-body layui-form">
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-cellphone" for="LAY-user-login-cellphone"></label>
                <input type="text" name="phoneNumber" id="LAY-user-login-cellphone" lay-verify="phone" placeholder="手机" class="layui-input">
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block" style="margin-left: 0px">
                    <label  class="layadmin-user-login-icon layui-icon layui-icon-auz" style="z-index: 20"></label>
                    <select name="roles" lay-verify="required" style="padding-left: 30px">
                        <option value="">请选择角色</option>
                        <option value="用户">用户</option>
                        <option value="管理员">管理员</option>
                        <option value="超级管理员">超级管理员</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-password"></label>
                <input type="password" name="password" id="LAY-user-login-password" lay-verify="pass" placeholder="密码" class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-repass"></label>
                <input type="password" name="repass" id="LAY-user-login-repass" lay-verify="required" placeholder="确认密码" class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-username" for="LAY-user-login-nickname"></label>
                <input type="text" name="username" id="LAY-user-login-nickname" lay-verify="username" placeholder="账号" class="layui-input">
            </div>
            <div class="layui-form-item">
            <div class="layui-input-block"  style="margin-left: 0px;height: 60px">
                <textarea   name="remarks" placeholder="请输入备注内容~~"  class="layui-textarea" style="min-height: 50px !important;"></textarea>
            </div>
            </div>
            <div class="layui-form-item">
                <input type="checkbox" name="agreement" lay-skin="primary" title="同意用户协议" checked=""><div class="layui-unselect layui-form-checkbox layui-form-checked" lay-skin="primary"><span>同意用户协议</span><i class="layui-icon layui-icon-ok"></i></div>
            </div>
            <div class="layui-form-item">
                <button class="layui-btn layui-btn-fluid" lay-submit="" lay-filter="LAY-user-reg-submit">注 册</button>
            </div>
            <div class="layui-trans layui-form-item layadmin-user-login-other">
                <label>社交账号注册</label>
                <a href="javascript:;"><i class="layui-icon layui-icon-login-qq"></i></a>
                <a href="javascript:;"><i class="layui-icon layui-icon-login-wechat"></i></a>
                <a href="javascript:;"><i class="layui-icon layui-icon-login-weibo"></i></a>

                <a href="/index.html" class="layadmin-user-jump-change layadmin-link layui-hide-xs">用已有帐号登入</a>
                <a href="/idnex.html" class="layadmin-user-jump-change layadmin-link layui-hide-sm layui-show-xs-inline-block">登入</a>
            </div>
        </from>
    </div>

    <div class="layui-trans layadmin-user-login-footer">

        <p>© 2018 <a href="http://www.layui.com/" target="_blank">邑大人事管理系统</a></p>

    </div>

</div>


<script src="./layui/layui.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>

<script>
    layui.use(['layer', 'form'], function(){

        var form = layui.form

        form.render();

        //提交
        form.on('submit(LAY-user-reg-submit)', function(obj){
            var field = obj.field;

            //确认密码
            if(field.password !== field.repass){
                return layer.msg('两次密码输入不一致');
            }

            //是否同意用户协议
            if(!field.agreement){
                return layer.msg('你必须同意用户协议才能注册');
            }


            console.log(field);

            //请求接口
            axios.post('/register', {
                username : field.username ,
                password : field.password ,
                phoneNumber : field.phoneNumber ,
                remarks : field.remarks ,
                roles : field.roles
            }).then(function (response) {

                console.log(response);

                if(response.data.status === 1){
                    return layer.msg(response.data.data);
                    window.location.href = "/main.html"
                }else {
                    return layer.msg(response.data.data);
                }


            }).catch(function (error) {
                    console.log(error);
            });

            return false;
        });
    });
</script>

</body>
</html>